package com.anuo.app.study.studyjava;


public class StudyOOP {

    public static void main(String[] args) {

    }

    //多态实例
    public static void studyPolymorphism() {
        Cat cat = new Cat();

        Dog dog = new Dog();
        doSomething(cat);
        doSomething(dog);
        //还有种写法不用abstract 关键字 见 https://www.javatpoint.com/runtime-polymorphism-in-java 搜索Animal关键字
    }

    public static void doSomething(Animal animal) {
        animal.Shout();
    }


    private static abstract class Animal {
        public Animal() {

        }

        public Animal(String name, int age) {

        }

        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public abstract void Shout();
    }

    private static class Cat extends Animal {
        public Cat() {
            super("", 59);
        }

        public void Shout() {
            System.out.println("猫叫");

        }

    }

    private static class Dog extends Animal {
        public Dog() {
            super("", 59);
        }

        public void Shout() {
            System.out.println("狗叫");
        }
    }

}


